using System;
using UnityEngine;
using UnityEngine.UI;
using VoxelGame.Character;

namespace PKGames.MiniGames.VoxelGame.UI.GameUI.Scripts.GamePanel
{
	[Serializable]
	public class ToolUi
	{
		[SerializeField]
		private Button _toolButton;

		[SerializeField]
		private Transform _toolTransform;

		[SerializeField]
		private CharacterToolsController.ToolData.Tools _toolType;

		[SerializeField]
		private Image _selectionOverlay;

		[SerializeField]
		private Image _toolImage;

		private Action<CharacterToolsController.ToolData.Tools> _onButtonClicked;

		public Transform ToolTransform => _toolTransform;

		public CharacterToolsController.ToolData.Tools ToolType => _toolType;

		public Image ToolImage => _toolImage;

		public void Setup(Action<CharacterToolsController.ToolData.Tools> onButtonClicked)
		{
			_onButtonClicked = onButtonClicked;
			_toolButton.onClick.AddListener(OnButtonClicked);
		}

		private void OnButtonClicked()
		{
			_onButtonClicked.Fire(_toolType);
		}

		public void UpdateSelection(CharacterToolsController.ToolData.Tools toolTypeSelected)
		{
			_selectionOverlay.gameObject.SetActive(_toolType == toolTypeSelected);
		}
	}
}
